﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DevExpress.XtraNavBar;
using HRM.DICTIONARY.DAL;

namespace HRM.DICTIONARY.UI
{
    public partial class xfrmxucAll : DevExpress.XtraEditors.XtraForm
    {
        #region Danh Mục Nhân Sự
        private xucPosition xucPosition;
        private xucProfessional xucProfessional;
        private xucDegree xucDegree;
        private xucJob xucJob;
        private xucNationality xucNationality;
        private xucEthnic xucEthnic;
        private xucReligion xucReligion;
        private xucRelative xucRelative;
        private xucEducation xucEducation;
        private xucLanguage xucLanguage;
        private xucInformatic xucInformatic;
        private xucSkill xucSkill;
        #endregion

        #region Cơ Cấu Tổ Chức
        private xucBranch xucBranch;
        private xucDepartment xucDepartment;
        private xucGroup xucGroup;
        #endregion

        #region Danh Mục Chấm Công
        private xucShift xucShift;
        private xucSymbol xucSymbol;
        private xucMachineList xucMachineList;
        private xucHoliday xucHoliday;
        #endregion

        #region Danh Mục Tính Lương
        private xucSalaryRank xucSalaryRank;
        private xucSalaryStep xucSalaryStep;
        private xucAllowance xucAllowance;
        #endregion

        #region Tiêu Chí Đánh Giá
        private xucGroupRate xucGroupRate;
        private xucRate xucRate;
        #endregion

        List<string> listActiveControlNameList = new List<string>();

        public xfrmxucAll()
        {
            InitializeComponent();
            this.KeyPreview = true;
            //StaticVariable.ERPEn = new EFERP.ERP_Entities();
            listActiveControlNameList.Add("Bạn chưa chọn bất kỳ danh mục nào");
            Excute("xucPosition");
        }

        public void Excute(string ucName)
        {
            switch (ucName)
            {

                #region Danh Mục Nhân Sự
                case "xucPosition":
                    //SYS_LOG.Insert("Danh Mục Ngoại Ngữ", "Xem");
                    gcControl.Visible = true;
                    gcControl.Text = bbiPosition.Caption;
                    if (xucPosition != null)
                    {
                        xucPosition.BringToFront();
                        break;
                    }
                    xucPosition = new xucPosition();
                    xucPosition.Dock = DockStyle.Fill;
                    gcControl.Controls.Add(xucPosition);
                    xucPosition.BringToFront();
                    break;

                case "xucProfessional":
                    //SYS_LOG.Insert("Danh Mục Ngoại Ngữ", "Xem");
                    gcControl.Visible = true;
                    gcControl.Text = bbiProfessional.Caption;
                    if (xucProfessional != null)
                    {
                        xucProfessional.BringToFront();
                        break;
                    }
                    xucProfessional = new xucProfessional();
                    xucProfessional.Dock = DockStyle.Fill;
                    gcControl.Controls.Add(xucProfessional);
                    xucProfessional.BringToFront();
                    break;
                case "xucDegree":
                    //SYS_LOG.Insert("Danh Mục Ngoại Ngữ", "Xem");
                    gcControl.Visible = true;
                    gcControl.Text = bbiDegree.Caption;
                    if (xucDegree != null)
                    {
                        xucDegree.BringToFront();
                        break;
                    }
                    xucDegree = new xucDegree();
                    xucDegree.Dock = DockStyle.Fill;
                    gcControl.Controls.Add(xucDegree);
                    xucDegree.BringToFront();
                    break;
                case "xucJob":
                    //SYS_LOG.Insert("Danh Mục Ngoại Ngữ", "Xem");
                    gcControl.Visible = true;
                    gcControl.Text = bbiJob.Caption;
                    if (xucJob != null)
                    {
                        xucJob.BringToFront();
                        break;
                    }
                    xucJob = new xucJob();
                    xucJob.Dock = DockStyle.Fill;
                    gcControl.Controls.Add(xucJob);
                    xucJob.BringToFront();
                    break;
                case "xucNationality":
                    //SYS_LOG.Insert("Danh Mục Ngoại Ngữ", "Xem");
                    gcControl.Visible = true;
                    gcControl.Text = bbiNationality.Caption;
                    if (xucNationality != null)
                    {
                        xucNationality.BringToFront();
                        break;
                    }
                    xucNationality = new xucNationality();
                    xucNationality.Dock = DockStyle.Fill;
                    gcControl.Controls.Add(xucNationality);
                    xucNationality.BringToFront();
                    break;
                case "xucEthnic":
                    //SYS_LOG.Insert("Danh Mục Ngoại Ngữ", "Xem");
                    gcControl.Visible = true;
                    gcControl.Text = bbiEthnic.Caption;
                    if (xucEthnic != null)
                    {
                        xucEthnic.BringToFront();
                        break;
                    }
                    xucEthnic = new xucEthnic();
                    xucEthnic.Dock = DockStyle.Fill;
                    gcControl.Controls.Add(xucEthnic);
                    xucEthnic.BringToFront();
                    break;
                case "xucReligion":
                    //SYS_LOG.Insert("Danh Mục Ngoại Ngữ", "Xem");
                    gcControl.Visible = true;
                    gcControl.Text = bbiReligion.Caption;
                    if (xucReligion != null)
                    {
                        xucReligion.BringToFront();
                        break;
                    }
                    xucReligion = new xucReligion();
                    xucReligion.Dock = DockStyle.Fill;
                    gcControl.Controls.Add(xucReligion);
                    xucReligion.BringToFront();
                    break;
                case "xucRelative":
                    //SYS_LOG.Insert("Danh Mục Ngoại Ngữ", "Xem");
                    gcControl.Visible = true;
                    gcControl.Text = bbiRelative.Caption;
                    if (xucRelative != null)
                    {
                        xucRelative.BringToFront();
                        break;
                    }
                    xucRelative = new xucRelative();
                    xucRelative.Dock = DockStyle.Fill;
                    gcControl.Controls.Add(xucRelative);
                    xucRelative.BringToFront();
                    break;
                case "xucEducation":
                    //SYS_LOG.Insert("Danh Mục Ngoại Ngữ", "Xem");
                    gcControl.Visible = true;
                    gcControl.Text = bbiEducation.Caption;
                    if (xucEducation != null)
                    {
                        xucEducation.BringToFront();
                        break;
                    }
                    xucEducation = new xucEducation();
                    xucEducation.Dock = DockStyle.Fill;
                    gcControl.Controls.Add(xucEducation);
                    xucEducation.BringToFront();
                    break;
                case "xucLanguage":
                    //SYS_LOG.Insert("Danh Mục Ngoại Ngữ", "Xem");
                    gcControl.Visible = true;
                    gcControl.Text = bbiLanguage.Caption;
                    if (xucLanguage != null)
                    {
                        xucLanguage.BringToFront();
                        break;
                    }
                    xucLanguage = new xucLanguage();
                    xucLanguage.Dock = DockStyle.Fill;
                    gcControl.Controls.Add(xucLanguage);
                    xucLanguage.BringToFront();
                    break;
                case "xucInformatic":
                    //SYS_LOG.Insert("Danh Mục Ngoại Ngữ", "Xem");
                    gcControl.Visible = true;
                    gcControl.Text = bbiInformatic.Caption;
                    if (xucInformatic != null)
                    {
                        xucInformatic.BringToFront();
                        break;
                    }
                    xucInformatic = new xucInformatic();
                    xucInformatic.Dock = DockStyle.Fill;
                    gcControl.Controls.Add(xucInformatic);
                    xucInformatic.BringToFront();
                    break;
                case "xucSkill":
                    //SYS_LOG.Insert("Danh Mục Ngoại Ngữ", "Xem");
                    gcControl.Visible = true;
                    gcControl.Text = bbiSkill.Caption;
                    if (xucSkill != null)
                    {
                        xucSkill.BringToFront();
                        break;
                    }
                    xucSkill = new xucSkill();
                    xucSkill.Dock = DockStyle.Fill;
                    gcControl.Controls.Add(xucSkill);
                    xucSkill.BringToFront();
                    break;
                #endregion

                #region Cơ Cấu Tổ Chức
                case "xucBranch":
                    //SYS_LOG.Insert("Danh Mục Ngoại Ngữ", "Xem");
                    gcControl.Visible = true;
                    gcControl.Text = bbiBranch.Caption;
                    if (xucBranch != null)
                    {
                        xucBranch.BringToFront();
                        break;
                    }
                    xucBranch = new xucBranch();
                    xucBranch.Dock = DockStyle.Fill;
                    gcControl.Controls.Add(xucBranch);
                    xucBranch.BringToFront();
                    break;

                case "xucDepartment":
                    //SYS_LOG.Insert("Danh Mục Ngoại Ngữ", "Xem");
                    gcControl.Visible = true;
                    gcControl.Text = bbiDepartment.Caption;
                    if (xucDepartment != null)
                    {
                        xucDepartment.BringToFront();
                        break;
                    }
                    xucDepartment = new xucDepartment();
                    xucDepartment.Dock = DockStyle.Fill;
                    gcControl.Controls.Add(xucDepartment);
                    xucDepartment.BringToFront();
                    break;

                case "xucGroup":
                    //SYS_LOG.Insert("Danh Mục Ngoại Ngữ", "Xem");
                    gcControl.Visible = true;
                    gcControl.Text = bbiGroup.Caption;
                    if (xucGroup != null)
                    {
                        xucGroup.BringToFront();
                        break;
                    }
                    xucGroup = new xucGroup();
                    xucGroup.Dock = DockStyle.Fill;
                    gcControl.Controls.Add(xucGroup);
                    xucGroup.BringToFront();
                    break;
                #endregion

                #region Danh Mục Chấm Công
                case "xucShift":
                    //SYS_LOG.Insert("Danh Mục Ngoại Ngữ", "Xem");
                    gcControl.Visible = true;
                    gcControl.Text = bbiShift.Caption;
                    if (xucShift != null)
                    {
                        xucShift.BringToFront();
                        break;
                    }
                    xucShift = new xucShift();
                    xucShift.Dock = DockStyle.Fill;
                    gcControl.Controls.Add(xucShift);
                    xucShift.BringToFront();
                    break;

                case "xucSymbol":
                    //SYS_LOG.Insert("Danh Mục Ngoại Ngữ", "Xem");
                    gcControl.Visible = true;
                    gcControl.Text = bbiSymbol.Caption;
                    if (xucSymbol != null)
                    {
                        xucSymbol.BringToFront();
                        break;
                    }
                    xucSymbol = new xucSymbol();
                    xucSymbol.Dock = DockStyle.Fill;
                    gcControl.Controls.Add(xucSymbol);
                    xucSymbol.BringToFront();
                    break;

                case "xucMachineList":
                    //SYS_LOG.Insert("Danh Mục Ngoại Ngữ", "Xem");
                    gcControl.Visible = true;
                    gcControl.Text = bbiMachine.Caption;
                    if (xucMachineList != null)
                    {
                        xucMachineList.BringToFront();
                        break;
                    }
                    xucMachineList = new xucMachineList();
                    xucMachineList.Dock = DockStyle.Fill;
                    gcControl.Controls.Add(xucMachineList);
                    xucMachineList.BringToFront();
                    break;

                case "xucHoliday":
                    //SYS_LOG.Insert("Danh Mục Ngoại Ngữ", "Xem");
                    gcControl.Visible = true;
                    gcControl.Text = bbiHoliday.Caption;
                    if (xucHoliday != null)
                    {
                        xucHoliday.BringToFront();
                        break;
                    }
                    xucHoliday = new xucHoliday();
                    xucHoliday.Dock = DockStyle.Fill;
                    gcControl.Controls.Add(xucHoliday);
                    xucHoliday.BringToFront();
                    break;

                #endregion

                #region Danh Mục Tính Lương
                case "xucSalaryRank":
                    //SYS_LOG.Insert("Danh Mục Ngoại Ngữ", "Xem");
                    gcControl.Visible = true;
                    gcControl.Text = bbiRank.Caption;
                    if (xucSalaryRank != null)
                    {
                        xucSalaryRank.BringToFront();
                        break;
                    }
                    xucSalaryRank = new xucSalaryRank();
                    xucSalaryRank.Dock = DockStyle.Fill;
                    gcControl.Controls.Add(xucSalaryRank);
                    xucSalaryRank.BringToFront();
                    break;

                case "xucSalaryStep":
                    //SYS_LOG.Insert("Danh Mục Ngoại Ngữ", "Xem");
                    gcControl.Visible = true;
                    gcControl.Text = bbiStep.Caption;
                    if (xucSalaryStep != null)
                    {
                        xucSalaryStep.BringToFront();
                        break;
                    }
                    xucSalaryStep = new xucSalaryStep();
                    xucSalaryStep.Dock = DockStyle.Fill;
                    gcControl.Controls.Add(xucSalaryStep);
                    xucSalaryStep.BringToFront();
                    break;

                case "xucAllowance":
                    //SYS_LOG.Insert("Danh Mục Ngoại Ngữ", "Xem");
                    gcControl.Visible = true;
                    gcControl.Text = bbiAllowance.Caption;
                    if (xucAllowance != null)
                    {
                        xucAllowance.BringToFront();
                        break;
                    }
                    xucAllowance = new xucAllowance();
                    xucAllowance.Dock = DockStyle.Fill;
                    gcControl.Controls.Add(xucAllowance);
                    xucAllowance.BringToFront();
                    break;

                #endregion

                #region Tiêu Chí Đánh Giá
                case "xucGroupRate":
                    //SYS_LOG.Insert("Danh Mục Ngoại Ngữ", "Xem");
                    gcControl.Visible = true;
                    gcControl.Text = bbiGroupRate.Caption;
                    if (xucGroupRate != null)
                    {
                        xucGroupRate.BringToFront();
                        break;
                    }
                    xucGroupRate = new xucGroupRate();
                    xucGroupRate.Dock = DockStyle.Fill;
                    gcControl.Controls.Add(xucGroupRate);
                    xucGroupRate.BringToFront();
                    break;

                case "xucRate":
                    //SYS_LOG.Insert("Danh Mục Ngoại Ngữ", "Xem");
                    gcControl.Visible = true;
                    gcControl.Text = bbiRate.Caption;
                    if (xucRate != null)
                    {
                        xucRate.BringToFront();
                        break;
                    }
                    xucRate = new xucRate();
                    xucRate.Dock = DockStyle.Fill;
                    gcControl.Controls.Add(xucRate);
                    xucRate.BringToFront();
                    break;
                #endregion

            }

            if ((listActiveControlNameList.Count == 0 || listActiveControlNameList == null || listActiveControlNameList.Last() != gcControl.Text) && !listActiveControlNameList.Contains(gcControl.Text))
                listActiveControlNameList.Add(gcControl.Text);
        }


        private void bbi_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            NavBarItem navItem = (NavBarItem)sender;
            Excute(navItem.Tag.ToString());
        }

        private void gcControl_ControlRemoved(object sender, ControlEventArgs e)
        {
            string strControlName = e.Control.Name;
            //MessageBox.Show(strControlName);
            switch (strControlName)
            {

                #region Danh Mục Nhân Sự
                case "xucPosition":
                    xucPosition = null;
                    gcControl.Controls.RemoveByKey(strControlName);
                    break;

                case "xucProfessional":
                    xucProfessional = null;
                    gcControl.Controls.RemoveByKey(strControlName);
                    break;

                case "xucDegree":
                    xucDegree = null;
                    gcControl.Controls.RemoveByKey(strControlName);
                    break;

                case "xucJob":
                    xucJob = null;
                    gcControl.Controls.RemoveByKey(strControlName);
                    break;

                case "xucNationality":
                    xucNationality = null;
                    gcControl.Controls.RemoveByKey(strControlName);
                    break;
                case "xucEthnic":
                    xucEthnic = null;
                    gcControl.Controls.RemoveByKey(strControlName);
                    break;
                case "xucReligion":
                    xucReligion = null;
                    gcControl.Controls.RemoveByKey(strControlName);
                    break;
                case "xucRelative":
                    xucRelative = null;
                    gcControl.Controls.RemoveByKey(strControlName);
                    break;
                case "xucEducation":
                    xucEducation = null;
                    gcControl.Controls.RemoveByKey(strControlName);
                    break;
                case "xucLanguage":
                    xucLanguage = null;
                    gcControl.Controls.RemoveByKey(strControlName);
                    break;
                case "xucInformatic":
                    xucInformatic = null;
                    gcControl.Controls.RemoveByKey(strControlName);
                    break;
                case "xucSkill":
                    xucSkill = null;
                    gcControl.Controls.RemoveByKey(strControlName);
                    break;
                #endregion

                #region Cơ Cấu Tổ Chức
                case "xucBranch":
                    xucBranch = null;
                    gcControl.Controls.RemoveByKey(strControlName);
                    break;

                case "xucDepartment":
                    xucDepartment = null;
                    gcControl.Controls.RemoveByKey(strControlName);
                    break;

                case "xucGroup":
                    xucGroup = null;
                    gcControl.Controls.RemoveByKey(strControlName);
                    break;
                #endregion

                #region Danh Mục Chấm Công
                case "xucShift":
                    xucShift = null;
                    gcControl.Controls.RemoveByKey(strControlName);
                    break;

                case "xucSymbol":
                    xucSymbol = null;
                    gcControl.Controls.RemoveByKey(strControlName);
                    break;

                case "xucMachineList":
                    xucMachineList = null;
                    gcControl.Controls.RemoveByKey(strControlName);
                    break;

                case "xucHoliday":
                    xucHoliday = null;
                    gcControl.Controls.RemoveByKey(strControlName);
                    break;

                #endregion

                #region Danh Mục Tính Lương
                case "xucSalaryRank":
                    xucSalaryRank = null;
                    gcControl.Controls.RemoveByKey(strControlName);
                    break;

                case "xucSalaryStep":
                    xucSalaryStep = null;
                    gcControl.Controls.RemoveByKey(strControlName);
                    break;

                case "xucAllowance":
                    xucAllowance = null;
                    gcControl.Controls.RemoveByKey(strControlName);
                    break;

                #endregion

                #region Tiêu Chí Đánh Giá
                case "xucGroupRate":
                    xucGroupRate = null;
                    gcControl.Controls.RemoveByKey(strControlName);
                    break;

                case "xucRate":
                    xucRate = null;
                    gcControl.Controls.RemoveByKey(strControlName);
                    break;
                #endregion
            }

            listActiveControlNameList.RemoveAt(listActiveControlNameList.Count-1);
            gcControl.Text = listActiveControlNameList.Last();
        }
    }
}